package com.ruoyi.user.controller;


import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.user.domain.LoginAppUser;
import com.ruoyi.user.service.AppTokenService;
import com.ruoyi.user.service.LoginService;
import com.ruoyi.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private AppTokenService appTokenService;
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginAppUser loginAppUser) throws Exception {
        LoginAppUser login = loginService.login(loginAppUser);
        return AjaxResult.success(appTokenService.createToken(loginAppUser));
    }

    @PostMapping("/getCode")
    public AjaxResult getCode(@RequestBody User user){
        loginService.getCode(user.getPhone());
        return AjaxResult.success();
    }
}
